'use strict';

const fs = require('fs');
const {sequelize,DataTypes,defineModel} = require('../db');

function getFiles(){
    let files = fs.readdirSync(__dirname);

    let js_file = files.filter(item =>{
        return item.endsWith('.js') && item !== 'index.js';
    });

    return js_file;

};

function registerModel(files){
    let obj = {};
    files.forEach(item=>{
        let modelname = item.substring(0,item.length-3);
        obj[modelname] = require(__dirname+'/'+item);
    });
    return obj;
};


let files = getFiles();
let obj = registerModel(files);


obj.sync = async ()=>{
    return sequelize.sync({force:true});
}

module.exports = obj;